package com.lcxw.hxzbcommon.common;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;

public class RoomUtils {

    /**
     * 生成房间状态的 redisKey
     * @param roomId roomId
     * @return roomStatus_redisKey
     */
    public static String get_RoomStatus_RedisKey(long roomId){
        return "room:"+roomId+":status";
    }

    /**
     * 生成房间内 推流的redis key；
     * @param roomId roomId
     * @return roomPushUrl_redisKey
     */
    public static String get_roomPushUrl_redisKey(long roomId){
        return "room:"+roomId+":pushUrl";
    }

    /**
     * 生成房间内推流的 推流地址
     * @param userId userId
     * @return roomPushUrl_redisValue
     */
    public static String get_roomPushUrl_redisValue(long userId){
        return "rtmp://push.52yuze.com/live/"+userId;
    }

    /**
     * 生成房间内的拉流的 redis key
     * @param roomId roomId
     * @return roomPullUrl_redisKey
     */
    public static String get_roomPullUrl_redisKey(long roomId){
        return "room:"+roomId+":pullUrl";
    }

    /**
     * 生成拉流地址
     * @param userId userId
     * @return roomPullUrl_redisValue
     */
    public static String get_roomPullUrl_redisValue(long userId){
        return "rtmp://pull.52yuze.com/live/"+userId;
    }

    //生成申请连麦的redisKey
    public static String get_applying_key(long roomId){
        return "room:"+roomId+":applying";
    }

    //生成连麦中redisKey
    public static String get_line_key(long roomId){
        return "room:"+roomId+":line";
    }

    //生成申请拍拍的redisKey
    public static String get_paipaiApplying_key(long roomId){
        return "room:"+roomId+":paipaiApplying";
    }

    //生成拍拍中的redisKey
    public static String get_paipai_key(long roomId){
        return "room:"+roomId+":paipai";
    }

    //生成房间内观众的 redisKey
    public static String get_roomViewer_redisKey(long roomId){
        return "room:"+roomId+":viewer";
    }

    //生成房间内观众的 redisKey
    public static String get_roomViewer_redisKey(String roomId){
        return get_roomViewer_redisKey(Long.parseLong(roomId));
    }

    //生成房间拍拍礼物设置的key
    public static String get_paipaiGift_redisKey(long roomId) {
        return "room:"+roomId+":paipaiGift";
    }

    //生成拍拍房间爆灯的 redisKey
    public static String get_baodeng_redisKey(long roomId) {
        return "room:"+roomId+":baodeng";
    }

    //生成拍拍房间爆灯倒计时的 redisKey
    public static String get_baodeng_countDown_redisKey(String roomId) {
        return "room:"+roomId+":baodengCountDown";
    }
    public static String get_baodeng_countDown_redisKey(long roomId) {
        return get_baodeng_countDown_redisKey( roomId+"");
    }

    //生成房间火力值的 redisKey
    public static String get_fire_redisKey(String roomId) {
        return "room:"+roomId+":fire";
    }
    public static String get_fire_redisKey(long roomId) {
        return get_fire_redisKey( roomId+"");
    }

    //生成拍拍礼物赠送记录的redisKey，主要用来存到map中，计算拍拍中，赠送礼物后是否加入到连麦。
    public static String get_paipaiSend_redisKey(long roomId) {
        return "room:"+roomId+":paipaiSend";
    }

    //记录爆灯是否已经重新开始的redisKey
    public static String get_IsRestartBaodeng_redisKey(String roomId){
        return "room:"+roomId+":isRestartBaodeng";
    }
    public static String get_IsRestartBaodeng_redisKey(long roomId){
        return "room:"+roomId+":isRestartBaodeng";
    }


    public static String[] chars = new String[] { "0", "1", "2", "3", "4", "5",
        "6", "7", "8", "9" };

    //生成唯一id的方法
    public static long generateShortUuid(int length) {
        StringBuffer shortBuffer = new StringBuffer();
        String uuid = UUID.randomUUID().toString().replace("-", "");
        for (int i = 0; i < length; i++) {
            String str = uuid.substring(i * 4, i * 4 + 4);
            int x = Integer.parseInt(str, 16);
            shortBuffer.append(chars[x % 0xA]);
        }
        return Long.parseLong(shortBuffer.toString());
    }

    public static void main(String[] args) throws IOException {
        for (int i = 0; i < 100000; i++) {

            File file = new File("D:\\id.txt");
            FileWriter fileWriter = new FileWriter(file,true);

            fileWriter.write(generateShortUuid(8)+"\n");
            fileWriter.flush();
            fileWriter.close();
        }
    }



}
